<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://jsptags.com/tags/navigation/pager" prefix="pg"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
<link href="<%=path%>/CSS/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=path%>/JQuery/jquery-1.8.2.js"></script>
<%@ include file="/WEB-INF/JSP/ajax.jsp"%>
<script type="text/javascript"
	src="<%=path%>/My97DatePicker/WdatePicker.js"></script>
<style type="text/css">
.seachform li label {line-height: 45px;color: #444444;}
.scinput {line-height: 10px;margin-top: 5px}
.scinput1 {margin-top: 5px;height: 30px;}
.scbtn {background: #57a0ff;border-radius: 20px;width: 110px;margin-top: 4px;height: 35px}
thead {background: #f2f2f2}
.tablelist2 th {height: 45px;background: none;}
.tablelist2 tr{height:45px;}
.tablelist2 tr th{height: 20px;border-left: 1px solid #dddee6;border-right: 1px solid #dddee6;color: #444444;text-align: center;}
.tou{background: #e4eafe}
.kh{border-bottom: 1px solid #dddee6;}
.shuju td{border-left: 1px solid #dddee6;border-right: 1px solid #dddee6;color: #787c88;text-align: center;}
.shuju:nth-child(odd){background: #ffffff}
.shuju:nth-child(even){background: #f3f5fb}
.shuju:last-child{border-bottom: 1px solid #dddee6;}
.shuju:HOVER {
	background: #fff6cd;
}
 .loading {
	 margin: 180px 650px;
            display: block;
            width: 65px;
            height: 65px;
            border: 1px solid #ddd;
            border-radius: 5px;
            opacity: .7;
	 background: url(<%=path%>/images/loading.gif) no-repeat;
        }

.scbtn {
	outline: none;
}
</style>
</head>
<body style="background: #f5f5f5;padding: 0 10px;">
	<div class="place" style="background: #f5f5f5; margin-top: 10px">
		<ul class="placeul">
			<li><a href="#">报表</a></li>
			<li><a href="#">财务报表</a></li>
			<li><a href="<%=path%>/DrivingSys/queryExaminationRoomIncome/look.action">考场收入统计表</a></li>
		</ul>
	</div>

	<div class="rightinfo"
		style="background: #fff; border-radius: 10px; height: 45px;">

		<form action="<%=path%>/DrivingSys/outXls" class="form" method="post" >
			<ul class="seachform">
				<li><label>开始时间</label><input class="scinput1" name="beginTime"
					type="text"
					onfocus="WdatePicker({maxDate:'#F{$dp.$D(\'datemax\')||\'%y-%M-%d\'}',dateFmt:'yyyy-MM'})"
					id="datemin" class="input-text Wdate" style="width: 150px;"
					value="${beginTime}"></li>
				<li><label>结束时间</label><input class="scinput1" name="endTime"
					type="text"
					onfocus="WdatePicker({minDate:'#F{$dp.$D(\'datemin\')}',maxDate:'%y-%M-%d',dateFmt:'yyyy-MM'})"
					id="datemax" class="input-text Wdate" style="width: 150px;"
					value="${endTime}">
					<input type="hidden" name="xls" id="xls" value="">
					<input type="hidden" name="fileNames" value="考场收入统计表">
					<input type="hidden" id="stu">
				</li>
				<li><label>&nbsp;</label><input name="" type="button"
                                                class="scbtn" value="立即查询" id="cx"/></li>
				<shiro:hasPermission name="/outXlsExaminationRoomIncome">
					<li><label>&nbsp;</label><input onclick="chargeCss()" type="submit" id="dc"
													class="scbtn" value="导出Excel" /></li>
				</shiro:hasPermission>
			</ul>
		</form>
	</div>

	<div style="width: 100%; overflow: auto; margin-bottom: 20px; margin-top: 30px; background: #fff; box-shadow: 0 0 10px #f2f2f2; min-height: 600px" class="div">
		<table class="tablelist2" style="width: 99.5%"id="table1">
			
		</table>
	</div>
	<div id="hidden" style="display: none">
	
	</div>
</body>
<script type="text/javascript">
 $(document).ready(function(){
	$('#table1').html("<tr><td class='loading'></td></tr>");
	var startTime = "${beginTime}";
	var endTime = "${endTime}";
	var str =''
		$.ajax({
			url: '<%=path%>/DrivingSys/queryExaminationRoomIncomeByTime',
	        type: "post",
	        data: {'startTime':startTime,'endTime':endTime},
	        dataType: "json",
	        async: true,
	        success:function(json){
	        	var list_time = new Array();  
	        	 str += '<tr style="display: none;" class="tou">'
	        	 str += '<th style="text-align: center;height:30px;" colspan= "'+(json.length*1+5)+'">考场收入统计表</th></tr>'
	         	 str += '<tr class="tou" id="twoRow"><th rowspan="2" style="height:21px;text-align:center;">培训类型</th><th rowspan="2" style="height:20px;text-align:center;">协议驾校</th>'
	        	for(var i = 0;i<json.length;i++){
	        		str +='<th colspan="2" class="kh" style="height:20px;text-align:center;">'+json[i]+'</th>' 
	        		list_time[i] = json[i]
	        	}
	         	str +='<th colspan="2"  class="kh" style="height:21px;text-align:center;">合计</th></tr><tr class="tou">'	
	         	for(var i = 0;i<json.length;i++){
	            	str +='<th style="height:20px;text-align:center;" class="scje">时长</th><th>金额(元)</th>'
	            }
				str+='<th style="height:22px;text-align:center;">时长</th><th style="height:22px;text-align:center;">金额(元)</th></tr>'
				//$("#table1").html(str)
				//$("#xls").val($(".div").html())
					 data(str,list_time) 
	        },
	        error:function(){alert("错误")}
		})
}) 

//改变样式
function chargeCss(){
	$("#hidden").html($(".div").html())
	$("#hidden table .tou th:nth-child(2)").css("width","15px");
	$("#hidden table .tou th:nth-child(1)").css("width","16px");
	$("#hidden table .tou th:nth-child(0)").css("width","16px");
	/* for(var i=0;i<num;i++){
		var s = 14;
		var e = 13;
		if(i % 2 != 0){
			s = s+1;
			$("#hidden table #twoRow th").eq(i+2).css("width",""+s+"px");
			 //$("#hidden table #twoRow th").eq(i+2).css("color","red");
		}else{
			e = e+1;
			 $("#hidden table #twoRow th").eq(i+2).css("width",""+e+"px");
			 //$("#hidden table #twoRow th").eq(i+2).css("color","blue");
		}
		
	}
	for(var a=0;a<num;a++){
		if(a % 2 != 0){
			$("#hidden table tr .scje").eq(a+2).css("width","10px");
		}else{
			$("#hidden table tr .scje").eq(a+2).css("width","15px");
		}
	} */
	
	$("#hidden table .tou th").css("text-align","center");
	 
	$("#hidden .shuju td:odd").css("text-align","center");
	$("#hidden .shuju td:even").css("text-align","center");
	
	$("#hidden .shuju td").css("font-size","11pt");
	$("#hidden .tou th").css("font-size","11pt");
	
	//$("#hidden table .tou th").css("font-family","宋体");
/* 	$("#hidden .shuju td:odd").css("height","16px");
	$("#hidden .shuju td:even").css("height","17px"); */
	
	//$("#hidden .shuju td:even").css("width","25px");
	
	$("#hidden .tou th").css("background","rgb(228,234,254)");
	$("#hidden #jx td").css("background","rgb(228,242,190)");
	$("#hidden #jx2 td").css("background","rgb(228,242,190)");
	$("#hidden #zj td").css("background","rgb(255,193,133)");
	$("#xls").val($("#hidden").html())
	
 }

$("#cx").click(function(){
	var startTime = $("#datemin").val();
	var endTime = $("#datemax").val();
	if(startTime == null || startTime == ''){
		alert("开始时间不能未空")
		return false
	}
	if(endTime == null || endTime == ''){
		alert("结束时间不能未空")
		return false
	}
	$('#table1').html("<tr><td class='loading'></td></tr>");
	var str =''
	$.ajax({
		url: '<%=path%>/DrivingSys/queryExaminationRoomIncomeByTime',
        type: "post",
        data: {'startTime':startTime,'endTime':endTime},
        dataType: "json",
        async: true,
        success:function(json){
        	var list_time = new Array();  
        	$("#stu").val(json.length);
        	 str += '<tr style="display: none;" class="tou">'
	        	 str += '<th style="text-align: center;height:30px;" colspan= "'+(json.length*2+4)+'">考场收入统计表</th></tr>'
	         	 str += '<tr class="tou" id="twoRow"><th rowspan="2" style="height:21px;text-align:center;">培训类型</th><th rowspan="2" style="height:20px;text-align:center;">协议驾校</th>'
	        	for(var i = 0;i<json.length;i++){
	        		str +='<th colspan="2" class="kh" style="height:20px;text-align:center;">'+json[i]+'</th>' 
	        		list_time[i] = json[i]
	        	}
	         	str +='<th colspan="2"  class="kh" style="height:21px;text-align:center;">合计</th></tr><tr class="tou">'	
	         	for(var i = 0;i<json.length;i++){
	            	str +='<th style="height:20px;text-align:center;" class="scje">时长</th><th class="scje">金额(元)</th>'
	            }
				str+='<th style="height:22px;text-align:center;">时长</th><th style="height:22px;text-align:center;">金额(元)</th></tr>'
				data(str,list_time)
            if (list_time.length > 20) {
                $(".tablelist2 tr td").css("width", "");
                $(".tablelist2").css("width", "auto");
                $(".tablelist2").css("white-space", "nowrap")
            }
				//$(".xls").html($())
        },
        error:function(){alert("错误")}
	})
})

function data(str,list_time){
	//计算考前模拟
	 $.ajax({
			url: '<%=path%>/DrivingSys/queryExaminationRoomIncomeData',
			type: "post",
			data: {'time':list_time},
			dataType: "json",
			async: false,
			success:function(json){
				//判断协议驾校是否未空
				if(typeof(json.drivingName) == 'undefined'){
					if(json.kqmnnull == null){
						
					}else if(json.kqmnnull[0].drivingName == null && json.kqmnnull[0].duration == null && json.kqmnnull[0].amount == null){
						str +='<tr class="shuju"><td>考前模拟</td>'
						str+='<td></td>';
						for(var t = 0;t <list_time.length;t++){
							str +='<td></td>'
							str +='<td></td>'
						}
						str+='<td></td>'
						str+='<td></td>' 
						str +='</tr>'
					}else{
						//判断未null的协议驾校是否有值
						str +='<tr class="shuju"><td>考前模拟</td>'
						str+='<td style="height:16px">--------</td>';
						//时长
						var sc = 0;
						//金额
						var je = 0;
						//放入数据
						for(var t = 0;t <list_time.length;t++){
							if(json.kqmnnull[t].duration == null){
								str +='<td style="height:16px"></td>'
							}else{
								str += '<td class="sc'+t+'">'+json.kqmnnull[t].duration+'</td>'
								sc = sc*1 +  json.kqmnnull[t].duration*1
								sc = decimal(sc,2)
							}
							if(json.kqmnnull[t].amount == null){
								str +='<td></td>'
							}else{
								str += '<td class="je'+t+'">'+json.kqmnnull[t].amount+'</td>'
								je = je*1 + json.kqmnnull[t].amount*1
								je = decimal(je,2)
							}
						}
						str+='<td class="hjsc">'+sc+'</td>'
						str+='<td class="hjje">'+je+'</td>' 
						str +='</tr>'
					}
				}else{
					//判断第一条是否未null的驾校
					if(json.kqmnnull == 'undefined'){
						//协议驾校有多少数据就跨多少行
						var row = json.drivingName.length*1
						str +='<tr class="shuju"><td rowspan="'+row+'">考前模拟</td>'
			        }else if(json.kqmnnull != null && json.kong == '1'){
			        	//协议驾校有多少数据就跨多少行
						var row = json.drivingName.length*1+1
						str +='<tr class="shuju"><td rowspan="'+row+'">考前模拟</td>'
			        }else if(json.kqmnnull != null && json.kong != '1'){
			        	//协议驾校有多少数据就跨多少行
						var row = json.drivingName.length*1
						str +='<tr class="shuju"><td rowspan="'+row+'">考前模拟</td>'
			        }else{
			        	
			        	//未空就放入值
						 str+='<td>'+json.drivingName[0]+'</td>'
						//时长
						var sc = 0;
						//金额
						var je = 0;
						  for(var t = 0;t <list_time.length;t++){
							if(json.kqmns0[t].duration == null){
								 str+='<td style="height:16px"></td>';
							}else{
								str +='<td class="sc'+t+'">'+json.kqmns0[t].duration+'</td>'
								sc = sc*1 + json.kqmns0[t].duration*1
								sc = decimal(sc,2)
							}
							if(json.kqmns0[t].amount == null){
								str+='<td ></td>';
							}else{
								str +='<td class="je'+t+'">'+json.kqmns0[t].amount+'</td>'
								je = je*1 + json.kqmns0[t].amount*1
								je = decimal(je,2)
							}
						}  
						str+='<td class="hjsc">'+sc+'</td>'
						str+='<td class="hjje">'+je+'</td>' 
			        }
					//判断协议驾校是否未null并且金额和时长未null
						if(json.kong == null){
							//放入第一条协议驾校
							 str+='<td style="height:16px">'+json.drivingName[0]+'</td>'
							//时长
							var sc = 0;
							//金额
							var je = 0;
							  for(var t = 0;t <list_time.length;t++){
								if(json.kqmns0[t].duration == null){
									 str+='<td></td>';
								}else{
									str +='<td class="sc'+t+'">'+json.kqmns0[t].duration+'</td>'
									sc = sc*1 + json.kqmns0[t].duration*1
									sc = decimal(sc,2)
								}
								if(json.kqmns0[t].amount == null){
									str+='<td ></td>';
								}else{
									str +='<td class="je'+t+'">'+json.kqmns0[t].amount+'</td>'
									je = je*1 + json.kqmns0[t].amount*1
									je = decimal(je,2)
								}
							}  
						    str+='<td class="hjsc">'+sc+'</td>'
							str+='<td class="hjje">'+je+'</td>' 
							//放入null的协议驾校
				        }else{
							 str+='<td style="height:16px">--------</td>';
							//时长
							var sc = 0;
							//金额
							var je = 0;
							  for(var q = 0;q < json.kqmnnull.length;q++){
								 if(json.kqmnnull[q].duration == null && json.kqmnnull[q].amount == null){
									str+='<td></td>';
							     	str+='<td></td>';
								 }else{
									if(json.kqmnnull[q].duration == null){
										str+='<td></td>';
									}else{
										 str+='<td class="sc'+q+'">'+json.kqmnnull[q].duration+'</td>';
										 sc = sc*1 + json.kqmnnull[q].duration*1
										 sc = decimal(sc,2)
									}
									if(json.kqmnnull[q].amount == null){
										 str+='<td></td>';
									}else{
										 str+='<td class="je'+q+'">'+json.kqmnnull[q].amount+'</td>';
										 je = je*1 + json.kqmnnull[q].amount*1
										 je = decimal(je,2)
									}
								 }
							 } 
							 str+='<td class="hjsc">'+sc+'</td>'
							 str+='<td class="hjje">'+je+'</td>' 
						}
					//循环放入初第一条驾校的值根据时间所有的值
					if(json.kqmnnull != null && json.kong == '1'){
						for(var j = 0;j < json.drivingName.length;j++){
							str +='<tr class="shuju">'
							str+='<td>'+json.drivingName[j]+'</td>'
							//时长
							var sc = 0;
							//金额
							var je = 0;
							 for(var t = 0;t <list_time.length;t++){
									for (var key in json) {
										if(('kqmns'+t) == key){
											if(json[key][j] == 'undefined'){
										 		str +='<td style="height:16px"></td>'
										 		str +='<td></td>'
										 	}else{
												if(json[key][j].duration == null){
													str +='<td></td>'
												}else{
													str +='<td class="sc'+t+'">'+json[key][j].duration+'</td>'
													 sc = sc*1 + json[key][j].duration*1
													 sc = decimal(sc,2)
												}
												if(json[key][j].amount == null){
													str +='<td></td>'
												}else{
													str +='<td class="je'+t+'">'+json[key][j].amount+'</td>'
													je = je*1 + json[key][j].amount*1
													je = decimal(je,2)
												}
										 	}
										}
									}
								}
							str+='<td class="hjsc">'+sc+'</td>'
							str+='<td class="hjje">'+je+'</td>' 
							str +='</tr>'
						}
					}else{
						//把所有的协议驾校的值放进去
						for(var j = 1;j < json.drivingName.length;j++){
							str +='<tr class="shuju">'
							str+='<td>'+json.drivingName[j]+'</td>'
							//时长
							var sc = 0;
							//金额
							var je = 0;
							 for(var t = 0;t <list_time.length;t++){
									for (var key in json) {
										if(('kqmns'+t) == key){
										 	if(json[key][j] == 'undefined'){
										 		str +='<td style="height:16px"></td>'
										 		str +='<td></td>'
										 	}else{
										 		if(json[key][j].duration == null || json[key][j].duration == 'undefined'){
													str +='<td></td>'
												}else{
													str +='<td class="sc'+t+'">'+json[key][j].duration+'</td>'
													 sc = sc*1 + json[key][j].duration*1
													 sc = decimal(sc,2)
												}
												if(json[key][j].amount == null){
													str +='<td></td>'
												}else{
													str +='<td class="je'+t+'">'+json[key][j].amount+'</td>' 
													je = je*1 + json[key][j].amount*1
													je = decimal(je,2)
												} 
										 	}
										}
									}
								}
							str+='<td class="hjsc">'+sc+'</td>'
							str+='<td class="hjje">'+je+'</td>' 
							str +='</tr>'
						}
					}
				}
				str +='<tr class="shuju" style="background:#e4f2be" id="jx">'
				str +='<td style="height:16px">小计</td>'
				str +='<td></td>'
				for(var t = 0;t <list_time.length;t++){
					str +='<td id="sc'+t+'" class="zjsc'+t+'"></td>'
					str +='<td id="je'+t+'" class="zjje'+t+'"></td>'
				}
				 str +='<td id="xjsc"></td>'
				 str +='<td id="xjje"></td>'
				 str +='</tr>'
				 $(".tablelist2").html(str) 
				 js(list_time.length)
			},
	        error:function(){alert("错误")}
		})
		//计算考前训练
		 	   $.ajax({
					url: '<%=path%>/DrivingSys/queryExaminationRoomIncomeData2', 
					type: "post",
					data: {'time':list_time},
					dataType: "json",
					async: false,
					success:function(json){
						var str2 = '';
						//判断协议驾校是否未空
						if(typeof(json.drivingName2) == 'undefined'){
							if(json.kqmnnull2 == null){
								
							}else if(json.kqmnnull2[0].drivingName == null && json.kqmnnull2[0].duration == null && json.kqmnnull2[0].amount == null){
								str2 +='<tr class="shuju"><td>考前模拟</td>'
								str2+='<td></td>';
									for(var t = 0;t <list_time.length;t++){
										str2 +='<td></td>'
										str2 +='<td></td>'
									}
									str2+='<td></td>'
									str2+='<td></td>' 
									str2 +='</tr>'
							}else{
								
								//判断未null的协议驾校是否有值
								str2 +='<tr class="shuju"><td>考前训练</td>'
								str2 +='<td style="height:16px">--------</td>';
								//时长
								var sc = 0;
								//金额
								var je = 0;
								//放入数据
								for(var t = 0;t <list_time.length;t++){
									if(json.kqmnnull2[t].duration == null){
										str2 +='<td></td>'
									}else{
										str2 += '<td class="sc2'+t+'">'+json.kqmnnull2[t].duration+'</td>'
										sc = sc*1 +  json.kqmnnull2[t].duration*1
										sc = decimal(sc,2)
									}
									if(json.kqmnnull2[t].amount == null){
										str2 +='<td></td>'
									}else{
										str2 += '<td class="je2'+t+'">'+json.kqmnnull2[t].amount+'</td>'
										je = je*1 + json.kqmnnull2[t].amount*1
										je = decimal(je,2)
									}
								}
								str2+='<td class="hjsc2">'+sc+'</td>'
								str2+='<td class="hjje2">'+je+'</td>' 
								str2 +='</tr>'
							}
						}else{
							//判断第一条是否未null的驾校
							if(json.kqmnnull2 == 'undefined'){
								//协议驾校有多少数据就跨多少行
								var row = json.drivingName2.length*1
								str2 +='<tr class="shuju"><td rowspan="'+row+'">考前训练</td>'
					        }else if(json.kqmnnull2 != null && json.kong2 == '1'){
					        	//协议驾校有多少数据就跨多少行
								var row = json.drivingName2.length*1+1
								str2 +='<tr class="shuju"><td rowspan="'+row+'">考前训练</td>'
					        }else if(json.kqmnnull2 != null && json.kong2 != '1'){
					        	//协议驾校有多少数据就跨多少行
								var row = json.drivingName2.length*1
								str2 +='<tr class="shuju"><td rowspan="'+row+'">考前训练</td>'
					        }else{
					        	
					        	//未空就放入值
								 str2+='<td style="height:16px">'+json.drivingName2[0]+'</td>'
								//时长
								var sc = 0;
								//金额
								var je = 0;
								  for(var t = 0;t <list_time.length;t++){
									if(json.kqmns20[t].duration == null){
										str2+='<td></td>';
									}else{
										str2 +='<td class="sc2'+t+'">'+json.kqmns20[t].duration+'</td>'
										sc = sc*1 + json.kqmns20[t].duration*1
										sc = decimal(sc,2)
									}
									if(json.kqmns20[t].amount == null){
										str2+='<td ></td>';
									}else{
										str2 +='<td class="je2'+t+'">'+json.kqmns20[t].amount+'</td>'
										je = je*1 + json.kqmns20[t].amount*1
										je = decimal(je,2)
									}
								}  
								  str2+='<td class="hjsc2">'+sc+'</td>'
								  str2+='<td class="hjje2">'+je+'</td>' 
					        }
							//判断协议驾校是否未null并且金额和时长未null
								if(json.kong2 == null){
									//放入第一条协议驾校
									 str2+='<td style="height:16px">'+json.drivingName2[0]+'</td>'
									//时长
									var sc = 0;
									//金额
									var je = 0;
									  for(var t = 0;t <list_time.length;t++){
										if(json.kqmns20[t].duration == null){
											str2+='<td></td>';
										}else{
											str2 +='<td class="sc2'+t+'">'+json.kqmns20[t].duration+'</td>'
											sc = sc*1 + json.kqmns20[t].duration*1
											sc = decimal(sc,2)
										}
										if(json.kqmns20[t].amount == null){
											str2+='<td ></td>';
										}else{
											str2 +='<td class="je2'+t+'">'+json.kqmns20[t].amount+'</td>'
											je = je*1 + json.kqmns20[t].amount*1
											je = decimal(je,2)
										}
									}  
									  str2+='<td class="hjsc2">'+sc+'</td>'
									  str2+='<td class="hjje2">'+je+'</td>' 
									//放入null的协议驾校
						        }else{
									 str2+='<td style="height:16px">--------</td>';
									//时长
									var sc = 0;
									//金额
									var je = 0;
									  for(var q = 0;q < json.kqmnnull2.length;q++){
										 if(json.kqmnnull2[q].duration == null && json.kqmnnull2[q].amount == null){
											 str2+='<td></td>';
											 str2+='<td></td>';
										 }else{
											if(json.kqmnnull2[q].duration == null){
												str2+='<td></td>';
											}else{
												str2+='<td class="sc2'+q+'">'+json.kqmnnull2[q].duration+'</td>';
												 sc = sc*1 + json.kqmnnull2[q].duration*1
												 sc = decimal(sc,2)
											}
											if(json.kqmnnull2[q].amount == null){
												str2+='<td></td>';
											}else{
												str2+='<td class="je2'+q+'">'+json.kqmnnull2[q].amount+'</td>';
												 je = je*1 + json.kqmnnull2[q].amount*1
												 je = decimal(je,2)
											}
										 }
									 } 
									  str2+='<td class="hjsc2">'+sc+'</td>'
									  str2+='<td class="hjje2">'+je+'</td>' 
								}
							//循环放入初第一条驾校的值根据时间所有的值
							if(json.kqmnnull2 != null && json.kong2 == '1'){
								for(var j = 0;j < json.drivingName2.length;j++){
									str2 +='<tr class="shuju">'
									str2 +='<td style="height:16px">'+json.drivingName2[j]+'</td>'
									//时长
									var sc = 0;
									//金额
									var je = 0;
									 for(var t = 0;t <list_time.length;t++){
											for (var key in json) {
												if(('kqmns2'+t) == key){
													if(json[key][j] == 'undefined'){
														str2 +='<td style="height:16px"></td>'
														str2 +='<td></td>'
												 	}else{
														if(json[key][j].duration == null){
															str2 +='<td></td>'
														}else{
															str2 +='<td class="sc2'+t+'">'+json[key][j].duration+'</td>'
															 sc = sc*1 + json[key][j].duration*1
															 sc = decimal(sc,2)
														}
														if(json[key][j].amount == null){
															str2 +='<td></td>'
														}else{
															str2 +='<td class="je2'+t+'">'+json[key][j].amount+'</td>'
															je = je*1 + json[key][j].amount*1
															je = decimal(je,2)
														}
												 	}
												}
											}
										}
									 str2+='<td class="hjsc2">'+sc+'</td>'
									 str2+='<td class="hjje2">'+je+'</td>' 
									 str2 +='</tr>'
								}
							}else{
								//把所有的协议驾校的值放进去
								for(var j = 1;j < json.drivingName2.length;j++){
									str2 +='<tr class="shuju">'
									str2+='<td style="height:16px">'+json.drivingName2[j]+'</td>'
									//时长
									var sc = 0;
									//金额
									var je = 0;
									 for(var t = 0;t <list_time.length;t++){
											for (var key in json) {
												if(('kqmns2'+t) == key){
												 	if(json[key][j] == 'undefined'){
												 		str2 +='<td style="height:16px"></td>'
												 		str2 +='<td></td>'
												 	}else{
												 		if(json[key][j].duration == null || json[key][j].duration == 'undefined'){
												 			str2 +='<td></td>'
														}else{
															str2 +='<td class="sc2'+t+'">'+json[key][j].duration+'</td>'
															 sc = sc*1 + json[key][j].duration*1
															 sc = decimal(sc,2)
														}
														if(json[key][j].amount == null){
															str2 +='<td></td>'
														}else{
															str2 +='<td class="je2'+t+'">'+json[key][j].amount+'</td>' 
															je = je*1 + json[key][j].amount*1
															je = decimal(je,2)
														} 
												 	}
												}
											}
										}
									 str2+='<td class="hjsc2">'+sc+'</td>'
									 str2+='<td class="hjje2">'+je+'</td>' 
									 str2 +='</tr>'
								}
							}
						}
						str2 +='<tr class="shuju" style="background:#e4f2be" id="jx2">'
						str2 +='<td style="height:16px">小计</td>'
						str2 +='<td></td>'
						for(var t = 0;t <list_time.length;t++){
							str2 +='<td id="sc2'+t+'" class="zjsc'+t+'"></td>'
							str2 +='<td id="je2'+t+'" class="zjje'+t+'"></td>'
						}
						str2 +='<td id="xjsc2"></td>'
						str2 +='<td id="xjje2"></td>'
						str2 +='</tr>' 
						$(".tablelist2").append(str2)
						js2(list_time.length); 
						//总计
						var str3 = '';
			 				str3 +='<tr class="shuju" style="background:#ffc185" id="zj">'
							str3 +='<td style="height:16px">总计</td>'
							str3 +='<td></td>'
							for(var t = 0;t <list_time.length;t++){
								str3 +='<td id="zjsc'+t+'"></td>'
								str3 +='<td id="zjje'+t+'"></td>'
							}
							str3 +='<td id="xjsc3"></td>'
							str3 +='<td id="xjje3"></td>'
							str3 +='</tr>'
							$(".tablelist2").append(str3)
							js3(list_time.length); 	
					},
			        error:function(){alert("错误")}
				}) 
				//$(".tablelist2").html(str) 
				/* $(".shuju td").css("height","21px");
	 			$(".shuju td").css("text-align","center");
	 			$(".shuju td").css("width","20px"); */ 
				//$("#xls").val($(".div").html())
}

//计算合计
function js3(num){
	for(var i = 0;i < num;i++){
		//计算合计时长
		var s = 0;
		$('.zjsc'+i+'').each(function(i) {
			if($(this).text() == '' || $(this).text() == null){
				
			}else{
				s = s*1 + $(this).text()*1;
			}
			s = decimal(s,2)
		})
		$('#zjsc'+i+'').text(s)
		
		//计算合计金额
		var a = 0;
		$('.zjje'+i+'').each(function(i) {
			if($(this).text() == '' || $(this).text() == null){
				
			}else{
				a = a*1 + $(this).text()*1;
			}
			a = decimal(a,2)
		})
		$('#zjje'+i+'').text(a)
	}
	//合计时长
	var sc = $("#xjsc").text();
	//合计金额
	var sc2 = $("#xjsc2").text();
	if(sc == null || sc == ''){
		$("#xjsc3").text(sc2);
	}else if(sc2 == null || sc2 == ''){
		$("#xjsc3").text(sc);
	}else{
		var zsc = sc*1 + sc2*1;
		$("#xjsc3").text(zsc);
	}
	
	//合计
	var je = $("#xjje").text();
	//合计金额
	var je2 = $("#xjje2").text();
	if(je == null || je == ''){
		$("#xjje3").text(je);
	}else if(je2 == null || je2 == ''){
		$("#xjje3").text(je2);
	}else{
		var zje = je*1 + je2*1;
		$("#xjje3").text(je2);
	}
}

//计算考前训练的时长，金额
function js2(num){
	for(var i = 0;i < num;i++){
		//计算时长
		var s = 0;
		$('.sc2'+i+'').each(function(i) {
			if($(this).text() == '' || $(this).text() == null){
				
			}else{
				s = s*1 + $(this).text()*1;
			}
			s = decimal(s,2)
		})
		$('#sc2'+i+'').text(s)
		//计算金额
		var j = 0;
		$('.je2'+i+'').each(function(i) {
			if($(this).text() == '' || $(this).text() == null){
				
			}else{
				j = j*1 + $(this).text()*1;
			}
			j = decimal(j,2)
		})
		$('#je2'+i+'').text(j)
	}
	//计算合计时长
	var xjsc = 0;
	$('.hjsc2').each(function(i) {
		if($(this).text() == '' || $(this).text() == null){
			
		}else{
			xjsc = xjsc*1 + $(this).text()*1;
		}
		xjsc = decimal(xjsc,2)
	})
	$("#xjsc2").text(xjsc)
	
	//计算合计金额
	var xjje = 0;
	$('.hjje2').each(function(i) {
		if($(this).text() == '' || $(this).text() == null){
			
		}else{
			xjje = xjje*1 + $(this).text()*1;
		}
		xjje = decimal(xjje,2)
	})
	$("#xjje2").text(xjje)
}

//计算考前模拟的时长，金额
function js(num){
	for(var i = 0;i < num;i++){
		//计算时长
		var s = 0;
		$('.sc'+i+'').each(function(i) {
			if($(this).text() == '' || $(this).text() == null){
				
			}else{
				s = s*1 + $(this).text()*1;
			}
			s = decimal(s,2)
		})
		$('#sc'+i+'').text(s)
		//计算金额
		var j = 0;
		$('.je'+i+'').each(function(i) {
			if($(this).text() == '' || $(this).text() == null){
				
			}else{
				j = j*1 + $(this).text()*1;
			}
			j = decimal(j,2)
		})
		$('#je'+i+'').text(j)
	}
	//计算合计时长
	var xjsc = 0;
	$('.hjsc').each(function(i) {
		if($(this).text() == '' || $(this).text() == null){
			
		}else{
			xjsc = xjsc*1 + $(this).text()*1;
		}
		xjsc = decimal(xjsc,2)
	})
	$("#xjsc").text(xjsc)
	
	//计算合计金额
	var xjje = 0;
	$('.hjje').each(function(i) {
		if($(this).text() == '' || $(this).text() == null){
			
		}else{
			xjje = xjje*1 + $(this).text()*1;
		}
		xjje = decimal(xjje,2)
	})
	$("#xjje").text(xjje)
}

//num是要处理的数字  v为要保留的小数位数
function decimal(num,v){
	var vv = Math.pow(10,v);
	return Math.round(num*vv)/vv;
}
</script>
</html>